<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui">

	<link type="text/css" rel="stylesheet" href="#{request.contextPath}/resources/css/users.css" />
	
	<h:form id="form_user_settings">
	
	<p:growl id="growl_users" globalOnly="true" autoUpdate="true" />  	
	<p:remoteCommand id="remoteCommand_search_users" name="searchUser" action="#{userBean.search}" 
		oncomplete="document.getElementById('form_user_settings:datatable_users:globalFilter').focus();" update=":form_user_settings"/>
	
	<p:dataTable id="datatable_users" var="user" value="#{userBean.users}" styleClass="datatable_users"
		 paginator="true" rows="15" paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"  
                 rowsPerPageTemplate="5,10,15" widgetVar="tableUsers" emptyMessage="#{msg.users_not_found}">
	
		  <f:facet name="header">  
            <p:outputPanel id="outputPanel_table_user_filter" style="float:right;">  
                <h:outputText value="#{msg.label_search}: " />  
                <p:inputText id="globalFilter" value="#{userBean.keyword}" onkeyup="if (this.value.length >= 3 || this.value.length == 0 ){ searchUser(); }" style="width:150px"
                	onfocus="var val=this.value; this.value=''; this.value= val;" />
            </p:outputPanel>  
        </f:facet>  
  
	
		<p:column id="column_login" >
			<f:facet name="header">
				#{msg.login_title}
			</f:facet>
			#{user.login}
		</p:column>

		<p:column  id="column_email">
			<f:facet name="header">
				#{msg.label_email}
			</f:facet>
			#{user.email}
		</p:column>	
		
		<p:column  id="column_status" >
			<f:facet name="header">
				#{msg.label_status}
			</f:facet>
			<h:outputText id="outputText_yes" value="#{msg.label_actived}" rendered="#{user.active}"/>
			<h:outputText id="outputText_no" value="#{msg.label_deactivate}" rendered="#{!user.active}"/>
		</p:column>	
		

		<p:column id="column_actions" >
			<f:facet name="header">
				#{msg.label_actions}
			</f:facet>
			<h:panelGrid id="panelgrid_user_actions" columns="4"  
				columnClasses="panelgrid_column,panelgrid_column,panelgrid_column,panelgrid_column">
			
				<p:commandLink id="commandbutton_edit"  styleClass="editbutton" action="#{userBean.prepareUpdate}" oncomplete="editUser.show()"
					update=":confirmDialog_EditUser">
					<f:setPropertyActionListener target="#{userBean.userEntity}" value="#{user}" />
				</p:commandLink>
				
				<p:commandLink id="commandbutton_aprove" styleClass="approvebutton"
				  	rendered="#{!user.active}" action="#{userBean.approve}" update=":form_user_settings">
				  	<f:setPropertyActionListener target="#{userBean.userEntity}" value="#{user}" />
				</p:commandLink>
				
				<p:commandLink id="commandbutton_desactive"  styleClass="disablebutton"
				rendered="#{user.active}" action="#{userBean.deactivate}" update=":form_user_settings">
					<f:setPropertyActionListener target="#{userBean.userEntity}" value="#{user}" />
				</p:commandLink>
				
				<p:commandLink id="commandbutton_delete" styleClass="deletebutton"
				  rendered="#{user.login != mainBean.loggedUser.login}" oncomplete="deleteUser.show()" action="#{userBean.prepareDelete}" update=":form_user_settings:confirmDialog_deleteUser">
					<f:setPropertyActionListener target="#{userBean.userEntity}" value="#{user}" />
				</p:commandLink>
				
			</h:panelGrid>
		</p:column>
			
	</p:dataTable>
	<p:confirmDialog id="confirmDialog_deleteUser" header="#{msg.label_user_delete}" message="#{msg.delete_user_question}" modal="true" 
		widgetVar="deleteUser">
			<h:panelGrid id="panelGrid_deleteUser" styleClass="panelGrid_editUser"
				columns="2">

				<h:outputText id="outputtext_edit_user_label_login"		value="#{msg.label_login}:" />
				<h:outputText id="outputtext_edit_user_label_login_value"	value="#{userBean.userEntity.login}" />
				
				<h:outputText id="outputtext_delete_user_label_email" 	value="#{msg.label_email}:" />
				<h:outputText id="outputtext_delete_user_label_email_value" 	value="#{userBean.userEntity.email}" />

				<p:commandButton id="commandbutton_delete_user"	value="#{msg.yes}" update="datatable_users"
					 action="#{userBean.delete}" oncomplete="deleteUser.hide()"/>
				<p:commandButton id="commandbutton_cancel" value="#{msg.no}"	onclick="deleteUser.hide()" />
			</h:panelGrid>
	</p:confirmDialog>
	</h:form>

	<p:dialog id="confirmDialog_EditUser" header="#{msg.edit_user}" modal="true" 
		widgetVar="editUser" width="500" height="230">
		<h:form id="form_edit_user">
			<h:panelGrid id="panelGrid_editUser" styleClass="panelGrid_editUser"
				columns="3">

				<h:outputText id="outputtext_edit_user_label_login"		value="#{msg.label_login}:" />
				<h:outputText id="outputtext_edit_user_label_login_value"	value="#{userBean.userEntity.login}" />
				<h:panelGroup id="panelGroup_edituser_random1" />
				
				<h:outputText id="outputtext_edit_user_label_email" 	value="#{msg.label_email}:" />
				<p:inputText id="outputtext_edit_user_label_email_value" value="#{userBean.newEmail}" validator="emailValidator"
					onblur="if (!isValidEmail(this.value)){alert('#{msg.invalid_email}');}"  />
				<p:message for="outputtext_edit_user_label_email_value" />
				
				<h:outputText id="outputtext_edit_user_label_password"	value="#{msg.label_password}:" />
				<p:password id="password_edit_user" value="#{userBean.newPassword}" match="passwordconfirm_edit_user"
					validatorMessage="#{msg.password_does_not_match}" />
				<h:panelGroup id="panelGroup_edituser_random3" />
					
				<h:outputText id="outputtext_edit_user_label_password_confirm"	value="#{msg.label_password_confirm}:" />
				<p:password id="passwordconfirm_edit_user"	value="#{userBean.newPassword}"  />
				<p:message for="password_edit_user" />
				
				<h:outputText id="outputText_edit_usertype" value="#{msg.label_user_type}:" />
				 <p:selectOneRadio id="selectOneRadio_user_type" value="#{userBean.userType}">  
            		<f:selectItems id="selectitems_user_types"  value="#{userBean.userTypes}"/>  
        		</p:selectOneRadio> 
        		<p:message for="selectOneRadio_user_type" />
				
				<p:commandButton id="commandbutton_save_user"	value="#{msg.label_save}" update="form_edit_user :form_user_settings"
					 action="#{userBean.update}" oncomplete="if (closeAfterRequest(xhr, status, args)) {editUser.hide();}" />
				<p:commandButton id="commandbutton_cancel" value="#{msg.label_cancel}" action="#{userBean.cancelEditUser}"
					onclick="editUser.hide()" update=":form_user_settings:datatable_users" />
			</h:panelGrid>

		</h:form>
	</p:dialog>
	
	
</html>